
package org.apache.ocean;

import java.util.concurrent.locks.*;
import java.util.concurrent.*;

/**
 *
 * @author  jason rutherglen
 */
public class LockUtil {
  public static long TIME = 10*1000;
  
  public LockUtil() {
  }
  
  public static void lock(Lock lock) {
    try {
      boolean success = lock.tryLock(TIME, TimeUnit.MILLISECONDS);
      if (!success) {
        throw new RuntimeException("tryLock timeout "+lock);
      }
    } catch (Throwable throwable) {
      throw new RuntimeException("locking had an error "+lock, throwable);
    }
  }
  
  public String toString(Lock lock) {
    if (lock instanceof ReentrantLock) {
      return lock.toString();
    } else if (lock instanceof ReentrantReadWriteLock.ReadLock) {
      ReentrantReadWriteLock.ReadLock readLock = (ReentrantReadWriteLock.ReadLock)lock;
      
    }
    return "";
  }
  
}
